#! /usr/bin/env node

const {existsSync,statSync,copyFileSync,readFileSync,readdirSync,mkdirSync,unlinkSync,rmdirSync} = require('fs');
const path = require('path');

const dirpath = process.cwd();
const args = process.argv;
// const rootpath = args[2];
// const newpath = args[3];
// const str = path.join(dirpath,rootpath)
// const str2 = path.join(dirpath,newpath)

// function dir(rootpath,newpath){
//     if(!existsSync(newpath)){
//         mkdirSync(newpath)
//     }
//     readdirSync(rootpath).map(item=>{
//         if(statSync(path.join(rootpath,item)).isDirectory()){
//             dir(path.join(rootpath,item),path.join(newpath,item))
//         }else{
//             copyFileSync(path.join(rootpath,item),path.join(newpath,item))
//         }
//     })
// }
// dir(str,str2)


// 删除
const commander = require('commander');
const inquirer = require('inquirer');

const arr=[{
    name:'del',
    type:'list',
    message:'是否',
    choices:[{
        name:'是',
        value:1
    },{
        name:'否',
        value:0
    }]
}]
commander
        .option('-a --add','aaa')
        .option('-d --del [name]','aaa')
        .action((name)=>{
            let d = name.del;
            if(existsSync(path.join(dirpath,d))){
                if(statSync(path.join(dirpath,d)).isDirectory()){
                    inquirer.prompt(arr).then(res=>{
                        let {del} = res;
                  
                        if(del){
                            delfile(path.join(dirpath,d))
                        }
                    })
                }else{
                    unlinkSync(path.join(dirpath,d))
                }
            }
        })
        .parse(process.argv)

// let option = commander.opts();
// if(option.add){
//     console.log(1)
// }
function delfile(delpath){
    let dir = readdirSync(delpath);
    console.log(dir)
    dir.map(item=>{
        if(statSync(path.join(delpath,item)).isDirectory()){
            delfile(path.join(delpath,item))
        }else{
            unlinkSync(path.join(delpath,item))
        }
    })
    rmdirSync(delpath)
}